<template>
  <div class="order-review-container">
    <h2>审核订单</h2>
    <el-table :data="orderList" style="width: 100%">
      <el-table-column prop="orderId" label="订单号" width="180" />
      <el-table-column prop="requestTime" label="申请时间" width="180" />
      <el-table-column prop="cancellationId" label="申请单号" />
      <el-table-column prop="refundAmount" label="退单金额" />
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button size="small" type="success" @click="handleApprove(scope.row)">同意</el-button>
          <el-button size="small" type="danger" @click="handleReject(scope.row)">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { ElMessage } from 'element-plus'
import querystring from 'querystring';
const orderList = ref([])

const fetchOrderList = async () => {
  try {
    const response = await axios.get('/api/staff/passOrders/listrequest')
    orderList.value = response.data.data
  } catch (error) {
    console.error('获取退款申请列表失败:', error)
    ElMessage.error('获取数据失败')
  }
}

const handleApprove = async (row) => {
  try {
    await axios.post('/api/staff/passOrders/pass',  querystring.stringify({cancellationId:row.cancellationId})
      
    )
    ElMessage.success('操作成功')
    fetchOrderList()
  } catch (error) {
    console.error('操作失败:', error)
    ElMessage.error('操作失败')
  }
}

const handleReject = async (row) => {
  try {
    await axios.post('/api/staff/passOrders/refuse', querystring.stringify({
      cancellationId:row.cancellationId,
    }))
    ElMessage.success('操作成功')
    fetchOrderList()
  } catch (error) {
    console.error('操作失败:', error)
    ElMessage.error('操作失败')
  }
}

onMounted(() => {
  fetchOrderList()
})
</script>

<style scoped>
.order-review-container {
  padding: 20px;
}
</style>